package com.itheima.api;

public class AnonymousTest {

    // 匿名对象
    public static void main(String[] args) {
        demo1();
        System.out.println(getDogObject().getName());
        System.out.println(demo2(new Dog("hello dog!!")));
    }

    //
    public static void demo1() {
        new Dog().setName("美国狗1");
        new Dog().setName("美国狗2");
        System.out.println(new Dog().getName());
    }


    // 匿名对象作为方法的参数和返回值
    public static Dog getDogObject() {
        return new Dog("hello dog!");
    }

    public static String demo2(Dog dog) {
        return dog.getName();
    }


}

// 测试匿名对象
class Dog {
    String name;

    public Dog() {

    }

    public Dog(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                '}';
    }
}
